﻿using Microsoft.AspNetCore.Mvc;
using NewLife.Caching;

namespace newlife.cache.api.Controllers
{
    /// <summary>
    /// Redis 方便操作
    /// </summary>
    public class RedisCacheConvenientController(FullRedis fullRedis) 
        : RedisBaseController(fullRedis)
    {
        [HttpPost]
        public IActionResult SetAll(string name)
        {
            var dict = new Dictionary<string, object>
            {
                ["Id"] = 1,
                ["Name"] = name
            };

            FullRedis.SetAll(dict, 60);
            return NoContent();
        }

        [HttpPost]
        public IActionResult GetAll(string[] keys)
        {
            return Ok(FullRedis.GetAll<string>(keys));
        }

        [HttpPost]
        public IActionResult Add(string key, string value)
        {
            return Ok(FullRedis.Add(key, value, 60)); // Key 存在返回 false
        }

        [HttpPost]
        public IActionResult Replace(string key, string value)
        {
            return Ok(FullRedis.Replace(key, value)); // 返回旧值
        }

        [HttpPost]
        public IActionResult Increment(string key)
        {
            return Ok(FullRedis.Increment(key, 1)); // 返回当前值
        }

        [HttpPost]
        public IActionResult Decrement(string key)
        {
            return Ok(FullRedis.Decrement(key, 1)); // 返回当前值
        }
    }
}
